STRIG Statements ---------------------------------------------------------------------------- Action Enable, disable, or suspend trapping of joystick activity. Syntax STRIG( n%) ON STRIG( n%) OFF STRIG( n%) STOP Remarks The argument n% is the trigger number as defined in the following table. ----------------------------------------------------------------------------- n Trigger Joystick ---------------------------------------------------------------------------- 0 Lower First 2 Lower Second 4 Upper First 6 Upper Second STRIG( n%) ON enables joystick-event trapping. If joystick trigger n% is pressed after a STRIG( n%) ON statement, the routine specified in the ON STRIG statement is executed. The STRIG( n%) OFF statement disables joystick-event trapping. No joystick event trapping takes place until a STRIG( n%) ON statement is executed. Events occurring while trapping is off are ignored. However, remembered events are lost if STRIG( n%) OFF is executed. The STRIG( n%) STOP statement suspends joystick-event trapping. No joystick-event trapping takes place until a STRIG( n%) ON statement is executed. Events occurring while trapping is suspended are remembered and processed when the next STRIG( n%) ON statement is executed. However, remembered events are lost if STRIG( n%) OFF is executed. When a joystick-event trap occurs (that is, the GOSUB is performed), an automatic STRIG STOP is executed so that recursive traps cannot take place. The RETURN operation from the trapping routine automatically performs a STRIG ON statement unless an explicit STRIG OFF was performed inside the routine. In previous versions of BASIC, the STRIG ON statement enabled testing of the joystick triggers; STRIG OFF disabled joystick-trigger testing. The current version of BASIC ignores the STRIG ON and STRIG OFF statements. For more information, see Chapter 9, "Event Handling" in the Programmer's Guide. Note The STRIG statement is not available for OS-2 protected mode. See Also ON event, STRIG Function Example The following example sets up joystick events for two triggers on each of two joysticks. It also displays the current x and y coordinate position of both joysticks. If any trigger is pressed, control is passed to a routine that indicates the state of the trigger; that is, whether the trigger is down or up. This example exercises the STRIG statements, the STRIG function, the ON STRIG statement, the STICK function, and the EVENT statements. ' Turn on event processing. EVENT ON ' Enable the upper and lower triggers on both joysticks. STRIG(0) ON 'Lower trigger, joystick A STRIG(2) ON 'Lower trigger, joystick B STRIG(4) ON 'Upper trigger, joystick A STRIG(6) ON 'Upper trigger, joystick B ' Set up joystick-event processing for each trigger. ON STRIG(0) GOSUB JoyTriggerHandler ON STRIG(2) GOSUB JoyTriggerHandler ON STRIG(4) GOSUB JoyTriggerHandler ON STRIG(6) GOSUB JoyTriggerHandler LOCATE 22, 6 PRINT "Press a trigger on either joystick to see a complete report." LOCATE 23, 20 PRINT "Press ANY keyboard key to end the program." ' Infinite loop waiting for a joystick event or keyboard input. DO LOOP WHILE INKEY$ = "" WrapItUp. CLS STRIG(0) OFF STRIG(2) OFF STRIG(4) OFF STRIG(6) OFF END JoyTriggerHandler. ' Print a label on screen. LOCATE 10, 14. PRINT "Joystick A" LOCATE 10, 45. PRINT "Joystick B" LOCATE 22, 1. PRINT STRING$(80, 32) DO IF STRIG(1) THEN ' Trigger 1, Joystick A. TriggerStatus$ = "DOWN" ELSE TriggerStatus$ = "UP " END IF EVENT OFF LOCATE 16, 10. PRINT "Trigger 1 is "; TriggerStatus$ EVENT ON IF STRIG(3) THEN ' Trigger 1, Joystick B. TriggerStatus$ = "DOWN" ELSE TriggerStatus$ = "UP " END IF EVENT OFF LOCATE 16, 42. PRINT "Trigger 1 is "; TriggerStatus$ EVENT ON IF STRIG(5) THEN ' Trigger 2, Joystick A. TriggerStatus$ = "DOWN" ELSE TriggerStatus$ = "UP " END IF EVENT OFF LOCATE 18, 10. PRINT "Trigger 2 is "; TriggerStatus$ EVENT ON IF STRIG(7) THEN ' Trigger 2, Joystick B. TriggerStatus$ = "DOWN" ELSE TriggerStatus$ = "UP " END IF EVENT OFF LOCATE 18, 42. PRINT "Trigger 2 is "; TriggerStatus$ EVENT ON GOSUB UpdateXY LOOP WHILE INKEY$ = "" RETURN WrapItUp UpdateXY. EVENT OFF LOCATE 12, 10. PRINT USING "X Position = ###"; STICK(0) LOCATE 14, 10. PRINT USING "Y Position = ###"; STICK(1) LOCATE 12, 42. PRINT USING "X Position = ###"; STICK(2) LOCATE 14, 42. PRINT USING "Y Position = ###"; STICK(3) EVENT ON RETURN